﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Base;
using UtilZ.Dotnet.Ex.DataStatistic;

namespace ConAppCore.Test
{
    internal class TestDataStatistic : IDataStatisticItem
    {


        public static void Test()
        {
            TestDataStatistic1();

            //TestDataStatisticManager();
        }

        private static void TestDataStatisticManager()
        {
            var dataStatisticGroup = new DataStatisticGroup<ushort>("xx", 3000, StatisticOutputCallback);
            DataStatisticManager.Default.CheckIntervalMilliseconds = 100;
            DataStatisticManager.Default.Add(new DataStatisticCallbackItem(dataStatisticGroup.OutputIntervalMilliseconds, StatisticOutputCallback2));
            DataStatisticManager.Default.Add(new TestDataStatistic());
            DataStatisticManager.Default.Add(dataStatisticGroup);
            dataStatisticGroup.AddValue(1, 10);
        }

        private static void TestDataStatistic1()
        {
            DataStatisticManager.Default.CheckIntervalMilliseconds = 100;

            var dataStatisticGroup1 = new DataStatisticGroup("xx1");
            dataStatisticGroup1.AddItem(new TestDataStatistic());
            dataStatisticGroup1.AddItem(new DataStatisticCallbackItem(2000, StatisticOutputCallback2));
            DataStatisticManager.Default.Add(dataStatisticGroup1);

            var dataStatisticGroup2 = new DataStatisticGroup<ushort>("xx2", 3000, StatisticOutputCallback);
            dataStatisticGroup2.AddValue(1, 10);
            DataStatisticManager.Default.Add(dataStatisticGroup2);

            Console.WriteLine("wait..");
            Console.ReadKey();
        }




        /// <summary>
        /// 根据时间间隔检查统计输出
        /// </summary>
        /// <param name="args">统计参数</param>
        void IDataStatisticItem.StatisticOutput(DataStatisticOutputArgs args)
        {
            Console.WriteLine($"111 {args.Duration}");
        }

        private static void StatisticOutputCallback2(DataStatisticOutputArgs args)
        {
            Console.WriteLine($"222 {args.Duration}");
        }

        private static void StatisticOutputCallback(DataStatisticOutputArgs args)
        {
            var item = (IDataStatisticItem<ushort>)args.StatisticItem;
            Console.WriteLine($"333 {args.Duration}");
        }
    }
}

